<!---->

<template>
  <div class="app-container">
    <div class="search-and-button">
      <el-button type="primary" icon="el-icon-plus" @click="showDialog">新增</el-button>
      <el-input v-model="search.keyword" placeholder="请输入关键字进行搜索" clearable @keyup.enter.native="getTableInfo()" @clear="getTableInfo()">
        <el-button slot="append" icon="el-icon-search" @click="getTableInfo()" />
      </el-input>
    </div>
    <el-row class="table">
      <el-table ref="tableData" v-loading="loading" :data="tableData" stripe border>
        <el-table-column type="selection" align="center"></el-table-column>
        <el-table-column align="center" type="index" label="索引" width="60px" />
        <el-table-column show-overflow-tooltip label="公司名称" prop="compName" />
        <el-table-column show-overflow-tooltip label="公司简称" prop="shortName" />
        <el-table-column show-overflow-tooltip label="联系人" prop="linkMan" />
        <el-table-column show-overflow-tooltip label="联系方式" prop="mobile" />
        <el-table-column show-overflow-tooltip label="官网地址" prop="webUrl">
          <template #default="{ row }">
            <el-link type="primary" :href="'http://' + row.webUrl" target="_blank">{{ row.webUrl }}</el-link>
          </template>
        </el-table-column>
        <el-table-column show-overflow-tooltip label="创建时间" prop="createAt" width="150px" />
        <el-table-column show-overflow-tooltip label="备注" prop="remark" />
        <el-table-column label="操作" fixed="right" align="center" width="100px">
          <template #default="{ row }">
            <el-button type="primary" icon="el-icon-edit" @click="showDialog(row)">编辑</el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-row>
    <el-row>
      <div class="table-btn-box">
        <el-button @click="() => {
              tableData.forEach(row => {
                $refs['tableData'].toggleRowSelection(row, true)
              })
            }
          ">选择全部</el-button>
        <el-button @click="
            () => {
              tableData.forEach(row => {
                $refs['tableData'].toggleRowSelection(row)
              })
            }
          ">反向选择</el-button>
        <el-button>
          更多菜单
          <i class="el-icon-arrow-down el-icon--right"></i>
        </el-button>
      </div>
      <pagination ref="Pagination" :total="total" :current.sync="search.current" :size.sync="search.size" @pagination="getTableInfo" />
    </el-row>

    <!-- 新增编辑 -->
    <addAndModify ref="addAndModify" @getTableInfo="getTableInfo" />
  </div>
</template>
<script>
import Pagination from '@/components/Pagination'
import addAndModify from './components'

export default {
  components: { Pagination, addAndModify },
  data() {
    return {
      loading: false,
      tableData: [],
      total: 0,
      search: {
        current: 1,
        size: 20,
        keyword: ''
      }
    }
  },
  computed: {},
  created() {},
  mounted() {
    this.getTableInfo()
  },
  methods: {
    /**
     * @description: page
     * @param {*} page
     * @return {*}
     */
    async getTableInfo(page = 1) {
      this.search.current = page
      this.loading = true
      const res = await this.$axios.post('/platform/comp/list', this.search)
      if (res?.data.code === 200) {
        this.tableData = res.data.data.list
        this.total = res.data.data.total
        setTimeout(() => {
          this.loading = false
        }, 100)
      } else {
        this.loading = false
      }
    },
    /**
     * @description: 新增编辑
     * @return {*}
     */
    showDialog(row) {
      this.$refs['addAndModify'].showDialog(row)
    }
  }
}
</script>
<style lang='scss' scoped>
.search-and-button {
  line-height: 30px;
  width: 100%;
  .el-input {
    width: 350px;
    float: right;
  }
}
.table {
  margin-top: 20px;
}
</style>
